package com.example.toastdialogdemo.slice;

import com.example.toastdialogdemo.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Component;
import ohos.agp.components.Switch;
import ohos.agp.utils.LayoutAlignment;
import ohos.agp.window.dialog.ToastDialog;

public class MainAbilitySlice extends AbilitySlice {
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);

        // 新建ToastDialog实例对象
        ToastDialog toastDialog = new ToastDialog(getContext());
        // 设置对话框的布局位置
        toastDialog.setAlignment(LayoutAlignment.CENTER);
        // 设置对话框位置的偏移量
        toastDialog.setOffset(0, 100);
        // 设置对话框显示的文案
        toastDialog.setText("这是一个对话框");

        // 新建switch组件
        Switch swith = new Switch(getContext());
        // 将自定义组件设置为对话框的内容
        toastDialog.setComponent(swith);
        // 弹出对话框
        toastDialog.show();



    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
